//
//  AXShoppingCartTableViewCell.m
//  hwacdx 购物车 cell
//
//  Created by hwacdx on 2019/4/30.
//  Copyright © 2019 hwacdx. All rights reserved.
//

#import "AXShoppingCartTableViewCell.h"

@interface AXShoppingCartTableViewCell()

/**
 勾选按钮
 */
@property (weak, nonatomic) IBOutlet UIButton *checkBtn;

/**
 商品标题文本
 */
@property (weak, nonatomic) IBOutlet UILabel *titleLabel;

/**
 商品图片
 */
@property (weak, nonatomic) IBOutlet UIImageView *iconView;

/**
 商品价格文本
 */
@property (weak, nonatomic) IBOutlet UILabel *priceLabel;

/**
 商品状态文本(已抢光时显示)
 */
@property (weak, nonatomic) IBOutlet UILabel *statusLabel;

/**
 商品是否有效
 */
@property (nonatomic) BOOL valid;

@end

@implementation AXShoppingCartTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (IBAction)buttonAction:(UIButton *)sender {
    
    self.isSelected = !self.isSelected;    
    if (_delegate && [_delegate respondsToSelector:@selector(shoppingCartTableViewCell_buttonActionAtIndexPath:tag:goodsNum:)]) {
        [_delegate shoppingCartTableViewCell_buttonActionAtIndexPath:self.indexPath tag:sender.tag goodsNum:@""];
    }
}

- (void)setIsSelected:(BOOL)isSelected{
    _isSelected = isSelected;
    
    if (!self.valid) {//失效商品
        [self.checkBtn setImage:[UIImage imageNamed:@"ic_loseefficacy"] forState:UIControlStateNormal];
    } else if (isSelected) {
        [self.checkBtn setImage:[UIImage imageNamed:@"ic_pitchon"] forState:UIControlStateNormal];
    } else {
        [self.checkBtn setImage:[UIImage imageNamed:@"ic_unchecked"] forState:UIControlStateNormal];
    }
}

- (void)setGoods:(AXHomeGoods *)goods valid:(BOOL)valid{     
    _valid = valid;
    _goods = goods;
    
    self.titleLabel.text = goods.name;
    self.priceLabel.text = [NSString stringWithFormat:@"¥%.2f", goods.price];
    
    //设置商品图片 
//    [AXImageViewTools configWithImageView:self.iconView urlStr:goods.cartImageUrl placeholderImage:kPlaceholderImage_90];
 
    if (self.valid) {//有效商品
        self.checkBtn.enabled = YES;
        self.statusLabel.hidden = YES;
        self.titleLabel.textColor = [UIColor blackColor];
        self.priceLabel.textColor = [UIColor redColor];
//        self.numberBtn.userInteractionEnabled = YES;
//        [self.numberBtn setIncreaseImage:[UIImage imageNamed:@"ic_add2"]];
//        [self.numberBtn setDecreaseImage:[UIImage imageNamed:@"ic_subtract"]];
        [self.checkBtn setImage:[UIImage imageNamed:@"ic_disagree"] forState:UIControlStateNormal];
        
    } else {//失效商品
        self.checkBtn.enabled = NO;
        self.statusLabel.hidden = NO;
        self.titleLabel.textColor = [UIColor lightGrayColor];
        self.priceLabel.textColor = [UIColor lightGrayColor];
//        self.numberBtn.userInteractionEnabled = NO;//禁止修改商品数量
//        [self.numberBtn setIncreaseImage:[UIImage imageNamed:@"ic_no_add"]];
//        [self.numberBtn setDecreaseImage:[UIImage imageNamed:@"ic_no_subtract"]];
        [self.checkBtn setImage:[UIImage imageNamed:@"ic_loseefficacy"] forState:UIControlStateNormal];
    }
    
    //设置商品数量
    //self.numberBtn.currentNumber = [goods.stock intValue];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
